# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        if root is None:
            return True
        return self.help(root, root)

    def help(self, left, right):
        if left is None:
            return True if right is None else False
        if right is None:
            return False
        if left.val != right.val:
            return False
        res = self.help(left.left, right.right)
        if res:
            return self.help(left.right, right.left)
        return False
